<template>
	<view>
		<ikz-loading :css-data="loading_css"></ikz-loading>
		<view class="ikz-top-bg">
			<image class="ikz-top-bg-img" :src="service_img"></image>
		</view>
		<view class="txt-box">
			<image src="/static/index/index-le.png" @click="toback" style="width: 80rpx;height: 80rpx;" mode=""></image>
			<view class="title_txt">
				<image src="/static/icon-search.png" style="width: 42rpx;height: 42rpx;" mode=""></image>
				<input type="text" placeholder="搜索" />
			</view>
		</view>

		<view class="tabbar_txt">
			<view class="left_box">
				<view class="tab-item" v-for="(item,index) in yuelist" :key="index" @click="hah(item,index)">
					<view :class="['tab-item', { selected: selectedIndices == index ? 'selected':''}]">
						{{ item.cate_name }}
					</view>
				</view>
			</view>

			<view class="right-box" @click="toguanli" v-if="selectedIndices == 0 || selectedIndices == 2">
				<image src="/static/new1.png" style="width: 22rpx;height: 22rpx;" mode=""></image>
				<view class="dtgl">
					最新发布
				</view>
			</view>

			<view class="right-box" @click="toguanli" v-if="selectedIndices == 1">
				<image src="/static/new1.png" style="width: 22rpx;height: 22rpx;" mode=""></image>
				<view class="dtgl">
					最早发布
				</view>
			</view>
		</view>

		<view class="cenbox">
			<scroll-view scroll-y :style="{ height: windowHeight }" @scrolltolower="onreachBottom">
				<view class="itembox" v-for="(item,index) in list" :key="index" v-if="selectedIndices == 0">
					<view class="topbox">
						<image :src="adminImgPath + item.avatar" style="width: 72rpx;height: 72rpx;border-radius: 50%;"
							mode="">
						</image>
						<view class="r-box">
							<view class="nametxt">
								{{item.nickname}}
							</view>
							<view class="timetxt">
								{{$utils.timestampToTime(item.createtime)}}发布
							</view>
						</view>
						<view class="tips" v-if="item.status == 0">
							寻找中
						</view>
						<view class="tips1" v-if="item.status == 1">
							已找到
						</view>
					</view>

					<view class="centerbox">
						<view class="dongtaitxt">
							<view class="wupin">
								<view class="ll-b">
									物品信息
								</view>
								<view class="ibfos">
									{{item.remark}}
								</view>
							</view>
							<view class="wupin">
								<view class="ll-b">
									遗失地点
								</view>
								<view class="ibfos">
									{{item.detail}}
								</view>
							</view>
							<view class="wupin">
								<view class="ll-b">
									联系方式
								</view>
								<view class="ibfos">
									v: {{item.mobile}}
								</view>
							</view>
						</view>
						<view class="imgbox">
							<image :src="adminImgPath+i" v-for="(i,k) in item.images" :key="k"
								style="width: 220rpx;height: 220rpx;border-radius: 16rpx;margin-bottom: 16rpx;margin-right: 10rpx;"
								mode=""></image>
						</view>
					</view>

					<view class="fpzbox" v-if="user_id == item.user_id  && item.status == 0">

						<view class="delbox" @click.stop="del(item.id)">
							删除
						</view>
						<view class="cancaebox" @click.stop="finds(item.id)">
							已找到
						</view>

					</view>
				</view>

				<view class="itembox" v-for="(item,index) in siwulist" :key="index" v-if="selectedIndices == 1">
					<view class="topbox">
						<image :src="adminImgPath + item.avatar" style="width: 72rpx;height: 72rpx;border-radius: 50%;"
							mode="">
						</image>
						<view class="r-box">
							<view class="nametxt">
								{{item.nickname}}
							</view>
							<view class="timetxt">
								{{$utils.timestampToTime(item.createtime)}}发布
							</view>
						</view>
						<view class="tips" v-if="item.status == 0">
							招领中
						</view>
						<view class="tips1" v-if="item.status == 1">
							已招领
						</view>
					</view>

					<view class="centerbox">
						<view class="dongtaitxt">
							<view class="wupin">
								<view class="ll-b">
									物品信息
								</view>
								<view class="ibfos">
									{{item.remark}}
								</view>
							</view>
							<view class="wupin">
								<view class="ll-b">
									遗失地点
								</view>
								<view class="ibfos">
									{{item.detail}}
								</view>
							</view>
							<view class="wupin">
								<view class="ll-b">
									联系方式
								</view>
								<view class="ibfos">
									v: {{item.mobile}}
								</view>
							</view>
						</view>
						<view class="imgbox">
							<image :src="adminImgPath+i" v-for="(i,k) in item.images" :key="k"
								style="width: 220rpx;height: 220rpx;border-radius: 16rpx;margin-bottom: 16rpx;margin-right: 10rpx;"
								mode=""></image>
						</view>

					</view>

					<view class="fpzbox">
						<view class="fpzbox" v-if="user_id == item.user_id  && item.status == 0">

							<view class="delbox" @click.stop="del(item.id)">
								删除
							</view>
							<view class="cancaebox" @click.stop="finds(item.id)">
								已找到
							</view>

						</view>
					</view>
				</view>

				<view class="itembox" v-for="(item,index) in mylist" :key="index" v-if="selectedIndices == 2">
					<view class="topbox">
						<image :src="adminImgPath + item.avatar" style="width: 72rpx;height: 72rpx;border-radius: 50%;"
							mode="">
						</image>
						<view class="r-box">
							<view class="nametxt">
								{{item.nickname}}
							</view>
							<view class="timetxt">
								{{$utils.timestampToTime(item.createtime)}}发布
							</view>
						</view>
						<view class="tips" v-if="item.status == 0">
							寻找中
						</view>
						<view class="tips1" v-if="item.status == 1">
							已找到
						</view>
					</view>

					<view class="centerbox">
						<view class="dongtaitxt">
							<view class="wupin">
								<view class="ll-b">
									物品信息
								</view>
								<view class="ibfos">
									{{item.remark}}
								</view>
							</view>
							<view class="wupin">
								<view class="ll-b">
									遗失地点
								</view>
								<view class="ibfos">
									{{item.detail}}
								</view>
							</view>
							<view class="wupin">
								<view class="ll-b">
									联系方式
								</view>
								<view class="ibfos">
									v: {{item.mobile}}
								</view>
							</view>
						</view>
						<view class="imgbox">
							<image :src="adminImgPath+i" v-for="(i,k) in item.images" :key="k"
								style="width: 220rpx;height: 220rpx;border-radius: 16rpx;margin-bottom: 16rpx;margin-right: 10rpx;"
								mode=""></image>
						</view>

						<view class="fpzbox" v-if="user_id == item.user_id  && item.status == 0">
						
							<view class="delbox" @click.stop="del(item.id)">
								删除
							</view>
							<view class="cancaebox" @click.stop="finds(item.id)">
								已找到
							</view>
						
						</view>

					</view>

				</view>
			</scroll-view>

		</view>

		<view class="favu" @click="tifabu">
			<image src="/static/index/fabu.png" style="width: 116rpx;height: 116rpx;border-radius: 50%;" mode="">
			</image>
		</view>
	</view>
</template>

<script>
	var app = getApp( );
	import ikz from '@/pages/Common/tools.js';
	export default {
		data( ) {
			return {
				adminImgPath: getApp( ).globalData.adminImgPath,
				loading_css: {
					display: 'flex'
				},
				service_img: '/static/index/bg.png',
				yuelist: [ {
					cate_name: '寻物启事'
				}, {
					cate_name: '失物招领'
				}, {
					cate_name: '我的发布'
				} ],
				selectedIndices: 0,
				windowHeight: 0,
				code: 1,
				page: 1,
				list: [ ],
				user_id: '',
				siwulist: [ ],
				mylist: [ ]
			};
		},
		onLoad( ) {
			var _this = this
			uni.getSystemInfo( {
				success: function( res ) {
					_this.windowHeight = res.windowHeight - 146 + 'px';
					console.log( res, '屏幕高度' );
				}
			} )
			this.user_id = uni.getStorageSync( 'user_info' ).user_id
		},
		onShow( ) {
			this.page = 1
			this.list = [ ]
			this.init( )
		},
		methods: {
			myinit( ) {
				var path = '/Announcement/index';
				var data = {
					token: uni.getStorageSync( 'local_user_session' ),
					// type: 1,
					order_type: 1,
					page: this.page,
					user_id: this.user_id
				};
				ikz.requestPost( path, data, res => {
					console.log( res, 'rrrr' );
					if ( res.data.code == 1 ) {
						this.mylist = res.data.data.data.map( item => {
							if ( item.images && typeof item.images === 'string' ) {
								item.images = item.images.split( ',' )
							}
							return item
						} )
						console.log( this.mylist, 'mylist' );
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )
			},
			siwu( ) {
				var path = '/Announcement/index';
				var data = {
					token: uni.getStorageSync( 'local_user_session' ),
					type: 1,
					order_type: 2,
					page: this.page
				};
				ikz.requestPost( path, data, res => {
					console.log( res, 'rrrr' );
					if ( res.data.code == 1 ) {
						this.siwulist = res.data.data.data.map( item => {
							if ( item.images && typeof item.images === 'string' ) {
								item.images = item.images.split( ',' )
							}
							return item
						} )
						console.log( this.siwulist, 'siwulist' );
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )
			},
			init( ) {
				var path = '/Announcement/index';
				var data = {
					token: uni.getStorageSync( 'local_user_session' ),
					type: 0,
					order_type: 1,
					page: this.page
				};
				ikz.requestPost( path, data, res => {
					console.log( res, 'rrrr' );
					if ( res.data.code == 1 ) {
						this.list = res.data.data.data.map( item => {
							if ( item.images && typeof item.images === 'string' ) {
								item.images = item.images.split( ',' )
							}
							return item
						} )
						console.log( this.list, 'list' );
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )
			},
			toback( ) {
				uni.switchTab( {
					url: '/pages/Home/index'
				} )
			},
			hah( item, index ) {
				console.log( index, '每一项' );
				this.selectedIndices = index

				if ( this.selectedIndices == 0 ) {
					this.init( )
				} else if ( this.selectedIndices == 1 ) {
					this.siwu( )
				} else if ( this.selectedIndices == 2 ) {
					this.myinit( )
				}

			},
			onreachBottom( e ) {
				console.log( e, 'e' );
			},
			tifabu( ) {
				uni.navigateTo( {
					url: '/pages/Home/xunwufabu/xunwufabu'
				} )
			},
			del( id ) {
				var path = '/Announcement/del';
				var data = {
					token: uni.getStorageSync( 'local_user_session' ),
					id: id,
				};
				ikz.request( path, data, res => {
					console.log( res, 'rrrr' );
					if ( res.data.code == 1 ) {
						uni.showToast( {
							title: res.data.msg,
							icon: 'none'
						} )
						this.init( )
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )
			},
			finds( id ) {
				var path = '/Announcement/editStatus';
				var data = {
					token: uni.getStorageSync( 'local_user_session' ),
					id: id,
					agent_id: uni.getStorageSync( 'default_agent' ).id,
				};
				ikz.request( path, data, res => {
					console.log( res, 'rrrr' );
					if ( res.data.code == 1 ) {
						uni.showToast( {
							title: res.data.msg,
							icon: 'none'
						} )
						this.init( )
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )
			},
			toguanli( ) {
				// uni.navigateTo( {
				// 	url: '/pages/Home/mydetails/mydetails'
				// } )
			}
		},
	}
</script>

<style lang="scss" scoped>
	.ikz-top-bg {
		position: fixed;
		top: 0px;
		left: 0px;
		z-index: -1;
	}

	.ikz-top-bg-img {
		width: 750rpx;
		height: 430rpx;
	}

	.txt-box {
		width: 100%;
		height: 82rpx;
		// margin: 110rpx auto 0px;
		margin-top: 90rpx;
		display: flex;

		.title_txt {
			width: 220rpx;
			height: 56rpx;
			background: #F5F5F5;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			font-weight: 500;
			font-size: 32rpx;
			color: #000000;
			text-align: left;
			line-height: 56rpx;
			// margin-left: 258rpx;
			z-index: 2;
			display: flex;
			align-items: center;
			padding: 0 20rpx;
			box-sizing: border-box;

			input {
				width: 178rpx;
				height: 56rpx;
			}
		}
	}



	.tabbar_txt {
		width: 100%;
		height: 62rpx;
		margin-top: 10rpx;
		// margin-left: 34rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		z-index: 2;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.left_box {
			width: 470rpx;
			height: 62rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 4rpx;
			box-sizing: border-box;

			.tab-item {
				width: 128rpx;
				height: 58rpx;
				line-height: 62rpx;
				text-align: center;
				font-weight: 400;
				font-size: 28rpx;
				color: #222222;

				.selected {
					/* 选中时的样式，比如背景色为红色 */
					font-weight: bold;
					color: #222;
					font-size: 32rpx;
					border-bottom: 8rpx solid #247EFF;
				}
			}
		}

		.right-box {
			width: 136rpx;
			height: 58rpx;
			display: flex;
			align-items: center;

			.dtgl {
				width: 104rpx;
				height: 58rpx;
				font-weight: 400;
				font-size: 26rpx;
				color: #222222;
				text-align: left;
				line-height: 58rpx;
				margin-left: 8rpx;
			}
		}

	}

	.cenbox {
		width: 100%;
		min-height: 500rpx;
		margin-top: 42rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		background-color: #fff;

		.itembox {
			width: 100%;
			min-height: 371rpx;
			padding: 26rpx 0;
			box-sizing: border-box;
			border-bottom: 20rpx solid #F5F5F5;

			.topbox {
				width: 100%;
				height: 72rpx;
				display: flex;
				align-items: center;
				border-bottom: 1rpx solid #F5F5F5;

				.r-box {
					width: 530rpx;
					height: 72rpx;
					margin-left: 8rpx;

					.nametxt {
						width: 100%;
						height: 38rpx;
						font-weight: 500;
						font-size: 26rpx;
						color: #222222;
						text-align: left;
					}

					.timetxt {
						width: 100%;
						height: 34rpx;
						font-weight: 300;
						font-size: 22rpx;
						color: #AFAFAF;
						text-align: left;
					}
				}

				.tips {
					width: 86rpx;
					height: 38rpx;
					background: #FF4F21;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					font-weight: 400;
					font-size: 22rpx;
					color: #FFFFFF;
					text-align: center;
					line-height: 38rpx;
				}

				.tips1 {
					width: 86rpx;
					height: 38rpx;
					background: #247EFF;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					font-weight: 400;
					font-size: 22rpx;
					color: #FFFFFF;
					text-align: center;
					line-height: 38rpx;
				}
			}

			.centerbox {
				width: 100%;
				min-height: 220rpx;
				margin-top: 26rpx;
				box-sizing: border-box;

				.dongtaitxt {
					width: 100%;
					min-height: 38rpx;

					.wupin {
						width: 100%;
						height: 38rpx;
						display: flex;
						align-items: center;
						margin-bottom: 24rpx;

						.ll-b {
							width: 88rpx;
							height: 34rpx;
							font-weight: 400;
							font-size: 22rpx;
							color: #AFAFAF;
							text-align: left;
						}

						.ibfos {
							width: 292rpx;
							height: 38rpx;
							font-weight: 400;
							font-size: 26rpx;
							color: #000000;
							text-align: left;
							margin-left: 22rpx;
						}
					}
				}

				.imgbox {
					width: 100%;
					min-height: 220rpx;
					display: flex;
					flex-wrap: wrap;
				}

				.btnboxss {
					width: 100%;
					height: 68rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.leftbtn {
						width: 320rpx;
						height: 68rpx;
						border-radius: 56rpx 56rpx 56rpx 56rpx;
						border: 2rpx solid #FF4F21;
						text-align: center;
						line-height: 68rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #FF4F21;
						text-align: center;
					}

					.wancheng {
						width: 320rpx;
						height: 68rpx;
						background: #B8D5FF;
						border-radius: 56rpx 56rpx 56rpx 56rpx;
						text-align: center;
						line-height: 68rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #247EFF;
						text-align: center;
					}
				}
			}

			.fpzbox {
				width: 100%;
				height: 92rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;



				.delbox {
					width: 320rpx;
					height: 68rpx;
					border-radius: 56rpx 56rpx 56rpx 56rpx;
					border: 2rpx solid #FF4F21;
					font-weight: 400;
					font-size: 24rpx;
					color: #FF4F21;
					text-align: center;
					line-height: 68rpx;
				}

				.cancaebox {
					width: 320rpx;
					height: 68rpx;
					background: #B8D5FF;
					border-radius: 56rpx 56rpx 56rpx 56rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #247EFF;
					text-align: center;
					line-height: 68rpx;
				}

			}
		}
	}

	.favu {
		width: 116rpx;
		height: 116rpx;
		position: fixed;
		bottom: 250rpx;
		right: 34rpx;
	}
</style>